//
//  PopOverPresentController.swift
//  weibopush
//
//  Created by 龚欣 on 15/6/27.
//  Copyright © 2015年 gong. All rights reserved.
//

import UIKit

class PopOverPresentController: UIPresentationController {

    lazy var dummyView : UIView = {
        let v = UIView()
        v.backgroundColor = UIColor(white: 0.0, alpha: 0.2)
        return v
        }()
    var presentFrame : CGRect = CGRectZero
    
    override init(presentedViewController: UIViewController, presentingViewController: UIViewController) {
        super.init(presentedViewController: presentedViewController, presentingViewController: presentingViewController)
        
        prepareDummyView()
       
    }
    
    func prepareDummyView(){
        let tap = UITapGestureRecognizer(target: self, action: "close")
        dummyView.addGestureRecognizer(tap)
    }
    
    func close(){

        presentedViewController.dismissViewControllerAnimated(true, completion: nil)
    
    }
    
    override func containerViewWillLayoutSubviews() {
        super.containerViewWillLayoutSubviews()
        
        dummyView.frame = containerView!.bounds
        containerView?.insertSubview(dummyView, atIndex: 0)
        
        presentedView()?.frame = presentFrame

    }
    
}
